/*
 *
 * =========================================================================
 *
 * Copyright (c) 2009-2010 Sperasoft, Inc. All rights reserved.
 * This software is the confidential and proprietary information of Sperasoft, Inc.
 * You shall not disclose such Confidential Information and shall use it only in
 * accordance with the terms of license agreement you entered into with Sperasoft, Inc.
 *
 * =========================================================================
 *
 * For more information, please see http://sperasoft.com
 *
 */
package org.shagin.jfin.core;

/**
 * The Class Coalesce.
 */
public class Coalesce {

	/**
	 * Coalesce.
	 * 
	 * @param args
	 *            the args
	 * 
	 * @return the t
	 */
	public static <T> T coalesce(T... args) {
		T result = null;
		for (int i = 0; i < args.length; i++) {
			if (null != args[i]) {
				result = args[i];
				break;
			}
		}
		return result;
	}

	/**
	 * Coalesce string.
	 * 
	 * @param args
	 *            the args
	 * 
	 * @return the string
	 */
	public static String coalesceString(String... args) {
		String result = null;
		for (int i = 0; i < args.length; i++) {
			if (!(null == args[i] || 0 == args[i].length())) {
				result = args[i];
				break;
			}
		}
		return result;
	}

}
